//
//  AppDelegate.m
//  Normal
//
//  Created by 8b410-2 on 16/12/9.
//  Copyright © 2016年 abb. All rights reserved.
//

#import "AppDelegate.h"
#import "OSCMainViewModel.h"
#import "AppThirdPartService.h"
#import "UIColor+Common.h"
#import "OSCViewModelServicesImpl.h"
#import <AFNetworking/AFNetworkReachabilityManager.h>
@interface AppDelegate ()

@property (nonatomic, strong) OSCViewModelServicesImpl *services;
@property (nonatomic, strong, readwrite) OSCNavigationControllerStack *navigationControllerStack;
@property (nonatomic, assign, readwrite) AFNetworkReachabilityStatus networkStatus;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    self.services = [[OSCViewModelServicesImpl alloc] init];
    self.navigationControllerStack = [[OSCNavigationControllerStack alloc] initWithServices:self.services];
    [self.services resetRootViewModel:[self createInitialViewModel]];
    [self.window makeKeyAndVisible];
    
    [self configureReachability];
    [self configureAppearance];

    return YES;
}
- (void)configureAppearance {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    NSDictionary *navbarTitleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    [[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    
    [[UITabBar appearance] setTintColor:[UIColor colorWithHex:0x24CF5F]];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x24cf5f]} forState:UIControlStateSelected];
    
    [[UINavigationBar appearance] setBarTintColor:[UIColor navigationbarColor]];
    [[UITabBar appearance] setBarTintColor:[UIColor titleBarColor]];
    
    [UISearchBar appearance].tintColor = [UIColor colorWithHex:0x15A230];
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setAlpha:0.6];
    
    UIPageControl *pageControl = [UIPageControl appearance];
    pageControl.pageIndicatorTintColor = [UIColor colorWithHex:0xDCDCDC];
    pageControl.currentPageIndicatorTintColor = [UIColor grayColor];
    
    [[UITextField appearance] setTintColor:[UIColor nameColor]];
    [[UITextView appearance]  setTintColor:[UIColor nameColor]];
}
- (void)configureReachability {
    RAC(self,networkStatus) = RACObserve([AFNetworkReachabilityManager sharedManager], networkReachabilityStatus);
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
}
- (OSCBaseViewModel *)createInitialViewModel {
    return [[OSCMainViewModel alloc] initWithServices:self.services params:nil];
}

@end
